package com.yuexunit.mobilenurse.module.BloodManage.presenter.impl;

import com.yuexunit.mobilenurse.module.BloodManage.bean.BloodDataBean;
import com.yuexunit.mobilenurse.module.BloodManage.bean.SingleBloodBag;
import com.yuexunit.mobilenurse.module.BloodManage.model.IBloodApplyModel;
import com.yuexunit.mobilenurse.module.BloodManage.presenter.IBloodApplyPresenter;
import com.yuexunit.mobilenurse.module.BloodManage.ui.Act_Blood_Apply_Joyree;
import com.yuexunit.mobilenurse.module.BloodManage.ui.fragment.Frag_Blood_Receive;
import com.yuexunit.mobilenurse.module.BloodManage.ui.view.IBloodApplyView;

import org.kymjs.kjframe.ui.ViewInject;

import java.util.Map;

import rx.Subscriber;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

/**
 * Created by work-jx on 2017/10/24.
 */
public class BloodApplyPresenter implements IBloodApplyPresenter{
    private IBloodApplyView view;
    private IBloodApplyModel model;

    public BloodApplyPresenter(IBloodApplyModel model, IBloodApplyView view) {
        this.model = model;
        this.view = view;
    }

    @Override
    public void getBloodDataList(Map<String, String> praise) {
        model.getBloodDataList(praise)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subscriber<BloodDataBean>() {
                               @Override
                               public void onCompleted() {

                               }

                               @Override
                               public void onError(Throwable e) {
                                   ViewInject.toast("获取用血信息失败");
                                   view.PullDownRefreshState(Act_Blood_Apply_Joyree.DOWNLOAD_NETERROR);
                                   view.PullDownRefreshState(Frag_Blood_Receive.DOWNLOAD_SUCCESS);
                               }

                               @Override
                               public void onNext(BloodDataBean bloodDataBean) {
                                   view.showBloodDataList(bloodDataBean);
                                   view.PullDownRefreshState(Frag_Blood_Receive.DOWNLOAD_SUCCESS);
                               }
                           }
                );
    }

    @Override
    public void getBloodBagData(Map<String, String> praise) {
        model.getBloodBagData(praise)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subscriber<SingleBloodBag>() {
                               @Override
                               public void onCompleted() {

                               }

                               @Override
                               public void onError(Throwable e) {
                                   ViewInject.toast("此血袋号数据获取失败");
                               }

                               @Override
                               public void onNext(SingleBloodBag singleBloodBag) {
                                   view.getBloodBagData(singleBloodBag);
                               }
                           }
                );
    }
}
